package controller;

import dao.PhoneDao;
import dao.impl.PhoneDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;

/**
 * 删除手机的功能
 */
@WebServlet("/removePhone.do")
public class RemovePhoneServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        PhoneDao phoneDao =  new PhoneDaoImpl();
        try {
            phoneDao.delectPhoneById(Integer.parseInt(id));
            resp.sendRedirect("/findAllPhone.do");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
